package com.wlld.yolo;

import java.util.ArrayList;
import java.util.List;

/**
 * @param
 * @DATA
 * @Author LiDaPeng
 * @Description
 */
public class DBSBody {
    private int center;//居中点坐标
    private List<Integer> pixels = new ArrayList<>();//邻域集合
    private int type;//居中点类别，1核心点，2，边界点,3,噪音点
    private int densityTh;//密度阈值
    private int density;//当前密度

    public DBSBody(int x, int y, int densityTh) {
        center = getPixel(x, y);//设置中心坐标
        this.densityTh = densityTh;
    }

    private int getPixel(int x, int y) {
        return (x << 12) | y;
    }

    public void setRegionPixel(int x, int y) {//输入邻域内坐标
        pixels.add(getPixel(x, y));
        density++;
    }

    public boolean isCore() {
        System.out.println("den:" + density + ",th==" + densityTh);
        if (density >= densityTh) {//核心点
            return true;
        } else {//非核心点
            return false;
        }
    }

    public boolean isIn(int key) {//判断邻域里是否存在该点
        return pixels.contains(key);
    }

    public double getCoreDist(int key) {//判断邻域里是否存在该点,若存在，则返回与核心点距离
        double dist = -1;
        if (isIn(key)) {
            int x = (key >> 12) & 0xFFF;
            int y = key & 0xFFF;
            int centerX = (center >> 12) & 0xFFF;
            int centerY = center & 0xFFF;
            dist = Math.sqrt(Math.pow(centerX - x, 2) + Math.pow(centerY - y, 2));
        }
        return dist;
    }
}
